www.gusucode.com > VC++网络版的打字软件源程序-源码程序 > VC++网络版的打字软件源程序-源码程序\code\TypeSrv V2.0\PrintManager.cpp
//Download by http://www.NewXing.com // PrintManager.cpp: implementation of the CPrintManager class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "TypeSrv.h" #include "PrintManager.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CPrintManager::CPrintManager() { m_nPointSize=120; m_nListRowHeight=100; m_nListCountPerPage=30; } CPrintManager::~CPrintManager() { if(m_ListFont.GetSafeHandle()!=NULL) m_ListFont.DeleteObject(); if(m_TitleFont.GetSafeHandle()!=NULL) m_TitleFont.DeleteObject(); } void CPrintManager::DrawPage(CDC* pDC,CListCtrl& ListCtrl, int nPage) { CRect rcTitle=GetTitleRect(); if(m_TitleFont.GetSafeHandle()!=NULL) m_TitleFont.DeleteObject(); m_TitleFont.CreatePointFont(2*m_nPointSize,"黑体",pDC); CFont* pOldFont=pDC->SelectObject(&m_TitleFont); pDC->DrawText("学生打字测试成绩",rcTitle,DT_SINGLELINE | DT_CENTER | DT_VCENTER); pDC->SelectObject(pOldFont); CRect rcList=GetListRect(); this->DrawList(pDC,ListCtrl,rcList,nPage); CRect rcFoot=GetFootRect(); CString str; str.Format("第%d页",nPage); pDC->DrawText(str,rcFoot,DT_SINGLELINE | DT_CENTER | DT_VCENTER); } void CPrintManager::Init(CDC *pDC,CListCtrl& ListCtrl) { m_nPageWidth=pDC->GetDeviceCaps(HORZRES); m_nPageHeight=pDC->GetDeviceCaps(VERTRES); int nItemCount=ListCtrl.GetItemCount(); if(m_ListFont.GetSafeHandle()!=NULL) m_ListFont.DeleteObject(); m_ListFont.CreatePointFont(m_nPointSize,"宋体",pDC); CFont* pOldFont=pDC->SelectObject(&m_ListFont); CSize sz=pDC->GetTextExtent("X"); m_nListRowHeight=sz.cy+20; m_nListCountPerPage=GetListRect().Height()/m_nListRowHeight; m_nMaxPage=nItemCount/m_nListCountPerPage; if(nItemCount>m_nListCountPerPage*m_nMaxPage) { m_nMaxPage++; } pDC->SelectObject(pOldFont); } CRect CPrintManager::GetDrawRect() { CRect rect(0,0,m_nPageWidth,m_nPageHeight); return rect; } void CPrintManager::DrawList(CDC *pDC, CListCtrl &ListCtrl, CRect rcList, int nCurPage) { CHeaderCtrl* pHeader=(CHeaderCtrl*)ListCtrl.GetDlgItem(0); int nColumnCount=pHeader->GetItemCount(); int nFirst=(nCurPage-1)*m_nListCountPerPage; int nLast=nCurPage*m_nListCountPerPage; CFont* pOldFont=pDC->SelectObject(&m_ListFont); CSize sz=pDC->GetTextExtent("X"); CRect rcItem(rcList); rcItem.bottom=rcItem.top+m_nListRowHeight; CRect rcAllLabels; ListCtrl.GetItemRect(nFirst,rcAllLabels,LVIR_BOUNDS); int nColumn; int x1=rcItem.left; int x2=rcItem.left; //////////////////////////////////////////////////////// //画表头 //////////////////////////////////////////////////////// pDC->MoveTo(rcItem.left,rcItem.bottom-1); pDC->LineTo(rcItem.left,rcItem.top-1); for(nColumn=0;nColumn<nColumnCount;nColumn++) { TCHAR buf[256]; HD_ITEM hdi; hdi.mask=HDI_TEXT | HDI_WIDTH; hdi.pszText=buf; hdi.cchTextMax=255; pHeader->GetItem(nColumn,&hdi); x2+=hdi.cxy*rcItem.Width()/rcAllLabels.Width(); CRect rcSubItem; rcSubItem.top=rcItem.top; rcSubItem.bottom=rcItem.bottom; rcSubItem.left=x1; rcSubItem.right=x2; x1=x2; CRect rcTextItem(rcSubItem); rcTextItem.left+=sz.cx; rcTextItem.right-=sz.cx; CString strText(buf); pDC->DrawText(strText,rcTextItem,DT_SINGLELINE | DT_VCENTER | DT_CENTER); pDC->MoveTo(rcSubItem.right-1,rcSubItem.bottom-1); pDC->LineTo(rcSubItem.right-1,rcSubItem.top-1); } pDC->MoveTo(rcItem.left,rcItem.top-1); pDC->LineTo(rcItem.right-1,rcItem.top-1); pDC->MoveTo(rcItem.left,rcItem.bottom-1); pDC->LineTo(rcItem.right-1,rcItem.bottom-1); /////////////////////////////////////////////////////////////////////////////// rcItem.OffsetRect(0,m_nListRowHeight); /////////////////////////////////////////////////////////////////////////// //画列表内容 /////////////////////////////////////////////////////////////////////////// for(int t=nFirst;t<nLast;t++) { x1=rcItem.left; x2=rcItem.left; pDC->MoveTo(rcItem.left,rcItem.bottom-1); pDC->LineTo(rcItem.left,rcItem.top-1); for(nColumn=0;nColumn<nColumnCount;nColumn++) { LV_COLUMN lvc; lvc.mask=LVCF_WIDTH; ListCtrl.GetColumn(nColumn,&lvc); x2+=lvc.cx*rcItem.Width()/rcAllLabels.Width(); CString strItemText=ListCtrl.GetItemText(t,nColumn); CRect rcSubItem; rcSubItem.top=rcItem.top; rcSubItem.bottom=rcItem.bottom; rcSubItem.left=x1; rcSubItem.right=x2; x1=x2; CRect rcTextItem(rcSubItem); rcTextItem.left+=sz.cx; rcTextItem.right-=sz.cx; pDC->DrawText(strItemText,rcTextItem,DT_SINGLELINE | DT_VCENTER | DT_CENTER); pDC->MoveTo(rcSubItem.right-1,rcSubItem.bottom-1); pDC->LineTo(rcSubItem.right-1,rcSubItem.top-1); } pDC->MoveTo(rcItem.left,rcItem.bottom-1); pDC->LineTo(rcItem.right-1,rcItem.bottom-1); rcItem.OffsetRect(0,m_nListRowHeight); } ///////////////////////////////////////////////////////////////////////////////////////// pDC->SelectObject(pOldFont); } CRect CPrintManager::GetListRect() { CRect rc(100,m_nListRowHeight*3,m_nPageWidth-100,m_nPageHeight-m_nListRowHeight*2); return rc; } CRect CPrintManager::GetTitleRect() { CRect rc(100,0,m_nPageWidth-100,m_nListRowHeight*3); return rc; } CRect CPrintManager::GetFootRect() { CRect rc(100,m_nPageHeight-m_nListRowHeight*2,m_nPageWidth-100,m_nPageHeight); return rc; }